package com.webreport.model;

import java.util.HashMap;
import java.util.Map;

public class QueryModel {
	private StringBuffer select = new StringBuffer();
	private StringBuffer where = new StringBuffer();
	private StringBuffer tables = new StringBuffer();
	private Map<String, Object> params = new HashMap<String, Object>();
	private int startrow;
	private int sizerow;
	public QueryModel(){
		
	}
	public QueryModel(String table,String where){
		this.appendTables(table);
		this.appendWhere(where);
	}
	public void addParam(String key, Object value) {
		params.put(key, value);
	}
	
	public StringBuffer appendSelect(String s) {
		return select.append(s);
	}
	
	public StringBuffer appendTables(String s) {
		if (tables.length() ==0)
			tables.append(" from ");
		return tables.append(s);
	}
	
	public void appendWhere(String s) {
		if (where.length() == 0) {
			where.append(" where ").append(s);
		} else {
			where.append(" and ").append(s);
		}
	}
	
	public String getSql() {
		return select.toString() + tables.toString() + where.toString();
	}
	
	public String getSqlCount() {
		return "select count(*) " + tables.toString() + where.toString();
	}
	
	public Map<String, Object> getParams() {
		return this.params;
	}

	public int getStartrow() {
		return startrow;
	}

	public void setStartrow(int startrow) {
		this.startrow = startrow;
	}

	public int getSizerow() {
		return sizerow;
	}

	public void setSizerow(int sizerow) {
		this.sizerow = sizerow;
	}
	
}
